package com.banach.prema.im.rest;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.banach.prema.im.util.CommonUtils;
import com.banach.prema.im.util.RestApiUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

@Service
public class C2CRestApi {
	@Autowired
	private RestApiUtils restApiUtil;
	
	public boolean sendBroadcastMsg(String sender,JSONArray receivers,JSONArray msgBody,JSONObject offlinePushInfo){
		JSONObject data = new JSONObject();
		data.put("SyncOtherMachine", 2);
		Random random = new Random();
		data.put("Random", CommonUtils.getRdm(8));
		if(sender!=null){
			data.put("From_Account", sender);
		}
		data.put("To_Account", receivers);
		data.put("MsgBody", msgBody);
		data.put("OfflinePushInfo", offlinePushInfo);

		JSONObject res = restApiUtil.doPost("/v4/openim/batchsendmsg", data);
		return "OK".equals(res.get("ActionStatus"));
	}
}
